package com.ckx.blog.controller;

import com.ckx.annotation.SysLog;
import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.UserDto;
import com.ckx.domain.dto.UserRegisterDto;
import com.ckx.domain.entity.User;
import com.ckx.domain.vo.UserInfoVo;
import com.ckx.service.UserService;
import com.ckx.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/userInfo")
    public ResponseResult userInfo(){

        Long userId = SecurityUtils.getUserId();
        UserInfoVo  userInfoVo  = userService.userInfo(userId);
        return ResponseResult.okResult(userInfoVo);
    }

    //更新用户信息
    @PutMapping("/userInfo")
    @SysLog(businessName = "更新用户信息")
    public ResponseResult updateUserInfo(@RequestBody UserDto userDto){

        userService.updateUserInfo(userDto);
        return ResponseResult.okResult();

    }

    //注册
    @PostMapping("/register")
    public ResponseResult register(@RequestBody UserRegisterDto userRegisterDto){
        userService.register(userRegisterDto);
        return ResponseResult.okResult();
    }

}
